﻿using Fleck;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
using WebSocketDemo.Job;
using WebSocketDemo.Tools;

namespace WebSocketDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化WebSocket
            var ws = WebSocketHelper.GetInstance();
            //while (true)
            //{
            //    ws.SendMsg(new MessageModel { MessageContent = $"Ticks:{DateTime.Now.Ticks}", Type = 1 });

            //    Thread.Sleep(2000);
            //}

            //从工厂中获取一个调度器实例化
            var scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();//开启调度器

            var job1 = JobBuilder.Create<PushMessageJob>()  //创建一个作业
                .WithIdentity("推送消息", "推送消息")
                .Build();

            var trigger1 = TriggerBuilder.Create()
                .WithIdentity("推送消息触发器", "推送消息触发器组")
                .StartNow()                        //现在开始
                //.WithCronSchedule("0 0/10 * ? * *")  //正式环境下10分钟一次
                .WithCronSchedule("0 0/1 * ? * *")  //每隔一定的时间执行
                .Build();


            //把作业，触发器加入调度器。
            scheduler.ScheduleJob(job1, trigger1);      //把作业，触发器加入调度器。

            var input = Console.ReadLine();
            //while (input != "exit")
            //{
            //    foreach (var socket in allSockets.ToList())
            //    {
            //        Test sa = new Test() { Name = input, Sex = "男" };
            //        var strJson=JsonConvert.SerializeObject(sa);
            //        socket.Send(strJson);
            //    }
            //    input = Console.ReadLine();
            //}
        }
    }
}
